package com.ymatou.iapi.sellerproduct.testcase;
import com.google.common.collect.Lists;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.ModifyLiveActivityBean;
import com.ymatou.iapi.liveseller.service.ModifyLiveActivityCall;
import com.ymatou.iapi.productmanager.parameter.SaveProductTemplateBean;
import com.ymatou.iapi.productmanager.parameter.SetPspStatusBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.ModifySellerProductRequest;
import com.ymatou.iapi.productmanager.service.ModifySellerProductCall;
import com.ymatou.iapi.productmanager.service.SaveProductTemplateCall;
import com.ymatou.iapi.productmanager.service.SetPspStatusCall;
import com.ymatou.iapi.productmanager.service.UpdateProductSensitiveWordCall;
import com.ymatou.iapi.productmongosync.service.MongocrudCall;
import com.ymatou.iapi.sellerproduct.parameter.MongocrudBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.model.*;
import com.ymttest.database.mongo.jproduct.*;
import com.ymttest.database.sqlwapper.*;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Ts_Mongocrud {
	private static MongocrudBean bean;
	private static MongocrudCall call;
	private static YmtProductActivityStockWapper productActStockWapper=new YmtProductActivityStockWapper();
	private static ModifyLiveActivityBean modifyliveactivityBean=new ModifyLiveActivityBean();
	private static ModifyLiveActivityCall modifyliveactivityCall=new ModifyLiveActivityCall();
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int globalSellerId = Integer.parseInt(EnvSetup.getData("globalSellerId"));
	
	private static ActivityProductsWapper productActivityStockWapper=new ActivityProductsWapper();
	private static ActivityProductsWapper activityProductsWapper=new ActivityProductsWapper();
	private  com.ymttest.database.mongo.jproduct.ProductTimeStampWapper productTimeStampWapper=new com.ymttest.database.mongo.jproduct.ProductTimeStampWapper();
	private static ProductsWapperV2 productsWapper;

	static {
		try {
			productsWapper = new ProductsWapperV2();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static ProductDescExtraNewWapper productDescExtraWapper=new ProductDescExtraNewWapper();
	private static LiveProductsWapper liveProductWapper=new LiveProductsWapper();
	private static LiveRoomWapper liveRoomWapper=new LiveRoomWapper();
	private static YmtCatalogsWapper catalogdWapper=new YmtCatalogsWapper();
	private static YmtProductsWapper productMapper=new YmtProductsWapper();
	
	private static YmtProductsWapper ymtproductsWapper=new YmtProductsWapper();
	
	private static YmtProductsInActivityWapper productInActivityWapper=new YmtProductsInActivityWapper();
	private YmtActivityWapper ymtActivityWapper=new YmtActivityWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("同步mongo");
	}
	
	@Before
	public void caseUp() {
		bean = new MongocrudBean();
		call = new MongocrudCall();	
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_001() {
		Logger.start(true,"同步mongo-验证指令SyncLiveActivityProduct,直播商品秒杀活动");
		try{
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);	
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
//			//修改价格和库存
//			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
//				ap.setActivityStock(ap.getActivityStock()-1);
//				ap.setActivityPrice(ap.getActivityPrice()-1);
//			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();
			
			//修改
			int iActivityID=modifyliveactivityBean.getLiveActivity().getLiveActivityId();
			int productInActivityId=modifyliveactivityBean.getLiveActivity().getActivityProducts().get(0).getActivityProductId();
			int transactionId=TestDataManager.getRandomIntNum(9);
			int stockNum=TestDataManager.getRandomIntNum(1);

			Map map=productActStockWapper.selectBy(MapUtil.hashMap("sproductid",productId,"iactivityid",iActivityID));
			int count=productActStockWapper.updateiStockNumByProductActivityStockId(map.get("sProductActivityStockID").toString(),stockNum);
			
			int source=Integer.parseInt(map.get("sourceId").toString())+1;
			
			productActStockWapper.updateSourceIdByProductActivityStockId(map.get("sProductActivityStockID").toString(),source);
			Logger.comment("stockNum######:"+stockNum);
	       
			//修改库存stock
			Thread.sleep(5000);
			bean.setActionType("SyncLiveActivityProduct");
			bean.setActivityId(productInActivityId);
			bean.setProductId(productId);
			bean.setTransactionId(transactionId);
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= productActivityStockWapper.getByProdId(productId);
			
			Logger.verifyEquals(new JSONArray(p.get("catalogs").toString()).getJSONObject(0).getString("stock")
					, Integer.toString(stockNum), "验证mongo返回的库存");
			Logger.verifyEquals(p.get("atype").toString(), "1", "验证atype返回的库存");
			Logger.verifyEquals(p.get("sourceId"), source, "验证sourceId返回的库存");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_002() {
		Logger.start(true,"同步mongo-验证指令CreateProduct,新增商品");
		try{	
			//发布一个活动商品		
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().setProductType(3);
			String productID1 = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.verifyNotNull(productID1, "响应报文-商品ID");

			bean.setActionType("CreateProduct");
			bean.setActivityId(0);
			bean.setProductId(productID1);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
			
		    //验证商品编号spid
		    Map<String,Object> p= productsWapper.getByProductId(productID1);
			Logger.verifyEquals(p.get("spid").toString(), productID1, "验证返回spid");
            Logger.verifyEquals(addpro.getProduct().getProductType(),Integer.parseInt(p.get("ptype").toString()), "验证传入的商品类型ptype与mongo数据库是否一致");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_002_1() {
		Logger.start(true,"同步mongo-验证指令CreateProduct,新增商品-全球优选商品");
		try{
			//发布一个活动商品		
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(globalSellerId);
			String productID1 = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.verifyNotNull(productID1, "响应报文-商品ID");

			bean.setActionType("CreateProduct");
			bean.setActivityId(0);
			bean.setProductId(productID1);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
			
		    //验证商品编号spid
		    Map<String,Object> p= productsWapper.getByProductId(productID1);
			Logger.verifyEquals(p.get("spid").toString(), productID1, "验证返回spid");
			//ptype=2是全球优选 gtype=1 是大礼包
            Logger.verifyEquals(2,Integer.parseInt(p.get("ptype").toString()),
            		"验证传入的商品类型ptype与mongo是否一致");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_002_2() {
		Logger.start(true,"同步mongo-验证指令CreateProduct,新增商品-大礼包");
		try{
			//发布一个活动商品		
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(globalSellerId);
			String productID1 = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			ProductManagerCallServiceV2.AddSellerGlobalPspProduct(globalSellerId,productID1,1);
			Logger.verifyNotNull(productID1, "响应报文-商品ID");

			bean.setActionType("CreateProduct");
			bean.setActivityId(0);
			bean.setProductId(productID1);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
			
		    //验证商品编号spid
		    Map<String,Object> p= productsWapper.getByProductId(productID1);
			Logger.verifyEquals(p.get("spid").toString(), productID1, "验证返回spid");
			//ptype=2是全球优选 gtype=1 是大礼包
            Logger.verifyEquals(2,Integer.parseInt(p.get("ptype").toString()),
            		"验证传入的商品类型ptype与mongo是否一致");
            Logger.verifyEquals(1,Integer.parseInt(p.get("gtype").toString()),
            		"验证传入的商品类型gtype与mongo是否一致");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_003() {
		Logger.start(true,"同步mongo-验证指令ModifyProduct,修改商品");
		try{
			YmtProductsWapper productWapper=new YmtProductsWapper();
			//获取当前时间&结束时间
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String startTime = YMTDateUtil.getBeforeOrNextDayStr(YMTDateUtil.getBeforeOrNextDay(0), 0);
			String endTime = YMTDateUtil.getBeforeOrNextDayStr(YMTDateUtil.getBeforeOrNextDay(7), 0);
			
			//发布一个活动商品		
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			//String productId = SellerProductCallService.addNewProductOnSale(sellerId2, sellerName2, null).getJSONObject("Data").getString("ProductId");
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.verifyNotNull(productId, "响应报文-商品ID");

			Logger.comment("productID1:"+productId);
			YmtProducts products=productWapper.selectProductByProductId(productId);
			//修改 
			String productName="测试mongo同步_"+startTime;
			products.setSproduct("测试mongo同步_"+startTime);
	        int count=productWapper.updateNameByProductId(products.getSproduct(),products.getSproductid());
			Logger.comment("count:"+count);
			
			
			bean.setActionType("ModifyProduct");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
			 //验证商品名称title
		    Map<String,Object> p= productsWapper.getByProductId(productId);
			Logger.verifyEquals(p.get("title").toString(), productName, "验证mongo返回的title");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_Mongocrud_004() {
		Logger.start(true,"同步mongo-验证指令UpdateLiveTimeForEs,更新扫货线程的商品直播时间");
		try{
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			LiveRoomCallService.UpdateLiveTimeToStart(createlive.getId());
			
//			Logger.comment("查询商品规格");
//			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
//			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
//			Logger.comment("创建秒杀活动");
//			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
//			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);	
//			
//			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
//			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
//			//修改价格和库存
//			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
//				ap.setActivityStock(ap.getActivityStock()-1);
//				ap.setActivityPrice(ap.getActivityPrice()-1);
//			});
//			modifyliveactivityCall.setData(modifyliveactivityBean);
//			modifyliveactivityCall.callService();
			
		   //获取商品在直播中的Id
			Map map=new LiveRoomWapper().selectLiveproductByLiveid(createlive.getId()).get(0);
			int liveProductId=Integer.parseInt(map.get("LiveProductId").toString());
			Logger.comment("liveProductId："+liveProductId);
	       
			//修改库存stock
			Thread.sleep(10000);
			bean.setActionType("UpdateLiveTimeForEs");
			bean.setActivityId(liveProductId);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
//	        //验证库存stock
//		    Map<String,Object> p= productActivityStockWapper.getByProdId(productId);
//			
//			Logger.verifyEquals(new JSONArray(p.get("catalogs").toString()).getJSONObject(0).getString("stock")
//					, Integer.toString(stockNum), "验证mongo返回的库存");
//			Logger.verifyEquals(p.get("atype").toString(), "1", "验证atype返回的库存");
//			Logger.verifyEquals(p.get("sourceId"), source, "验证sourceId返回的库存");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_005() {
		Logger.start(true,"同步mongo-验证指令AddProduct,添加商品（批量）");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
	       
			//修改库存stock
			Thread.sleep(5000);
			bean.setActionType("AddProduct");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证
		    Map<String,Object> p= productsWapper.getByProductId(productId);
			
			Logger.verifyEquals(p.get("spid").toString()
					, productId, "验证mongo返回的商品id");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_006() {
		Logger.start(true,"同步mongo-验证指令AddProductPics,添加商品图片");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
		
			List<String> productPicList=addpro.getProduct().getProductPicList();
			productPicList.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_ll.jpg");
			addpro.getProduct().setProductPicList(productPicList);
			ModifySellerProductRequest modifySellerProductRequest=ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId,addpro);
			ModifySellerProductCall modifySellerProductCall=new ModifySellerProductCall();
			modifySellerProductCall.setData(modifySellerProductRequest);
			modifySellerProductCall.callService();
			
			//修改库存stock
			Thread.sleep(5000);
			bean.setActionType("AddProductPics");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= productsWapper.getByProductId(productId);
		    Logger.verifyEquals(new JSONArray(p.get("pics").toString()).get(new JSONArray(p.get("pics").toString()).length()-1)
					, productPicList.get(productPicList.size()-1), "验证mongo返回的图片");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_007() {
		Logger.start(true,"同步mongo-验证指令BatchSetOnShelf,批量商品上架");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> productIds=Lists.newArrayList();
			productIds.add(productId);
			ProductManagerCallServiceV2.batchSetProductOnSale(productIds, sellerId);
			//batchSetProductOnSale
			//修改库存stock
			Thread.sleep(5000);
			bean.setActionType("BatchSetOnShelf");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= productsWapper.getByProductId(productId);
		    
		    Date dt = new Date();   
		    SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		    
		    Logger.comment("newstart1:"+YMTDateUtil.getFromDTSDate(p.get("newstart").toString(),""));
		    Logger.comment("newstart2:"+YMTDateUtil.parseYMDHMSDate(formatDate.format(dt)));
		    Logger.verifyEquals(true, YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getFromDTSDate(p.get("newstart").toString(),""))
		    		.before(YMTDateUtil.parseYMDHMSDate(formatDate.format(dt))), "验证newstart");
//		    Logger.verifyEquals(true, YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getFromDTSDate(p.get("newend").toString(),""))
//		    		.compareTo(YMTDateUtil.parseYMDHMSDate(formatDate.format(dt)))>=0, "验证newend");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_008() {
		Logger.start(true,"同步mongo-验证指令UpdatePromotionName,修改报名活动名称");
		try{
			
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
			String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String startTime = YMTDateUtil.getBeforeOrNextDayStr(YMTDateUtil.getBeforeOrNextDay(0), 0);
			String productName="修改报名活动名称指令测试_"+startTime;
			new YmtActivityWapper().updateSaleSideName(activityId,productName);

			
			bean.setActionType("UpdatePromotionName");
			bean.setActivityId(activityId);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
			 //验证mongo
		    Map<String,Object> p= activityProductsWapper.getByProdId(productId);
		    Map<String,Object> p2= productTimeStampWapper.getByProductId(productId);
			Logger.verifyEquals(p.get("aname").toString(), productName, "验证mongo 表 activityProducts 返回的活动名称");
			Logger.verifyNotNull(p2.get("aut").toString(), "验证mongo 表 productTimeStamp 返回的uat");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_009() {
		Logger.start(true,"同步mongo-验证指令DeleteProduct,删除商品");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> productIds=Lists.newArrayList();
			productIds.add(productId);
			ProductManagerCallServiceV2.batchDeleteProducts(productIds, sellerId);
			//batchSetProductOnSale
			//修改库存stock
			Thread.sleep(5000);
			bean.setActionType("DeleteProduct");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= productsWapper.getByProductId(productId);
		    
		    Logger.verifyIsNull(p,"验证mongo没有数据");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_010() {
		Logger.start(true,"同步mongo-验证指令DeleteProductPics,删除某个商品下的图片(单选/多选)");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Map<String,Object> p1= productsWapper.getByProductId(productId);
			
			List<String> productPicList=addpro.getProduct().getProductPicList();
			productPicList.remove(0);
			addpro.getProduct().setProductPicList(productPicList);
			
			List<String> productIds=Lists.newArrayList();
			productIds.add(productId);
			ModifySellerProductRequest modifySellerProductRequest=ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId, addpro);
			
			ModifySellerProductCall modifySellerProductCall=new ModifySellerProductCall();
			modifySellerProductCall.setData(modifySellerProductRequest);
			modifySellerProductCall.callService();
			
			//修改库存stock
			Thread.sleep(5000);
			bean.setActionType("DeleteProductPics");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p2= productsWapper.getByProductId(productId);
		    
		    Logger.verifyEquals(true,new JSONArray(p1.get("pics").toString()).length()-new JSONArray(p2.get("pics").toString()).length()==1
					, "验证mongo返回的图片");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_011() {
		Logger.start(true,"同步mongo-验证指令ProductPutout,商品下架");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> productIds=Lists.newArrayList();
			productIds.add(productId);
			ProductManagerCallServiceV2.batchSetProductOffSale(productIds, sellerId);
			//batchSetProductOnSale
			//修改库存stock
			Thread.sleep(5000);
			bean.setActionType("ProductPutout");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= productsWapper.getByProductId(productId);
		    
		    Date dt = new Date();   
		    SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		    Logger.verifyEquals(true, YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getFromDTSDate(p.get("newend").toString(),""))
		    		.before(YMTDateUtil.parseYMDHMSDate(formatDate.format(dt))), "验证newend");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_012() {
		Logger.start(true,"同步mongo-验证指令ProductStockChange,修改商品库存和价格");
		try{
			
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.verifyNotNull(productId, "响应报文-商品ID");

			Logger.comment("productID1:"+productId);
			
			YmtCatalogs catalogs=catalogdWapper.selectBySproductId(productId);
			//修改 
			ProductManagerCallServiceV2.updateProductStockNum(sellerId, productId, catalogs.getScatalogid(), 1);
			Logger.comment("CatalogId:"+catalogs.getScatalogid());
			bean.setActionType("ProductStockChange");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
			 //验证stock
		    Map<String,Object> p= new CatalogsWapper().getByCatalogId(catalogs.getScatalogid());
			Logger.verifyEquals(p.get("stock").toString(), "1", "验证stock返回的库存");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_013() {
		Logger.start(true,"同步mongo-验证指令UpdateSensitiveWord,更新商品敏感词");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			ModifySellerProductRequest modifySellerProductRequest=ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId, addpro);
			modifySellerProductRequest.getProduct().setProductName("测试商品名称SB");//关键子是SB
			ModifySellerProductCall modifySellerProductCall=new ModifySellerProductCall();
			modifySellerProductCall.setData(modifySellerProductRequest);
			modifySellerProductCall.callService();
			
			new UpdateProductSensitiveWordCall().call(productId, sellerId, 1, "SB");//propertyType（1- 商品名称，2- 商品文描文字部分，3- 规格名称，4-套装名称， 5-买家须知，6-买手介绍）
			
			//修改库存stock
			bean.setActionType("UpdateSensitiveWord");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p1= productsWapper.getByProductId(productId);
		    Logger.verifyEquals("测试商品名称**",p1.get("title").toString(), "验证mongo返回的商品名称");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_Mongocrud_014() {
		Logger.start(true,"同步mongo-验证指令SetOffTop,设置取消推荐置顶商品,与 Ymt_ProductsInLive（商品关联直播表） 有关，此功能已经不存在");
		try{
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			Logger.comment("####createlive.getId()######:"+createlive.getId());
			Logger.comment("####productId######:"+productId);
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);	
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();
			LiveRoomWapper liveroomWapper=new LiveRoomWapper();
			Map mapliveroom=liveroomWapper.selectLiveproductByIdAndPid(createlive.getId(), productId).get(0);
			Logger.comment("liveProductId:"+Integer.parseInt(mapliveroom.get("LiveProductId").toString()));
			int count=liveroomWapper.updateLiveProductStatusById(Integer.parseInt(mapliveroom.get("LiveProductId").toString()), 0, 1, 0);
			
			//修改库存stock
			bean.setActionType("SetOffTop");
			bean.setActivityId(modifyliveactivityBean.getLiveActivity().getLiveActivityId());
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();	 
			//直播商品更新-istop,status
//			//验证库存stock
//		    Map<String,Object> p1= liveProductWapper.getByProductId(productId);
//		    Logger.verifyEquals("0",p1.get("istop").toString(), "验证mongo返回的置顶字段istop");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_Mongocrud_015() {
		Logger.start(true,"同步mongo-验证指令SetOnTop,设置推荐置顶商品,与 Ymt_ProductsInLive（商品关联直播表） 有关，此功能已经不存在");
		try{
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);	
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();
			LiveRoomWapper liveroomWapper=new LiveRoomWapper();
			Map mapliveroom=liveroomWapper.selectLiveproductByIdAndPid(createlive.getId(), productId).get(0);
			Logger.comment("liveProductId:"+Integer.parseInt(mapliveroom.get("LiveProductId").toString()));
			int count=liveroomWapper.updateLiveProductStatusById(Integer.parseInt(mapliveroom.get("LiveProductId").toString()), 1, 1, 0);
			
			//修改库存stock
			bean.setActionType("SetOnTop");
			bean.setActivityId(modifyliveactivityBean.getLiveActivity().getLiveActivityId());
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();	        
			//验证库存stock
		    Map<String,Object> p1= liveProductWapper.getByProductId(productId);
		    Logger.verifyEquals("1",p1.get("istop").toString(), "验证mongo返回的置顶字段istop");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_016() {
		Logger.start(true,"同步mongo-验证指令ModifyPutawayProductInfo,修改上架商品信息(批量)");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> productIds=Lists.newArrayList();
			productIds.add(productId);
			ProductManagerCallServiceV2.batchSetProductOnSale(productIds, sellerId);
			//修改库存stock
			Thread.sleep(10000);
			bean.setActionType("ModifyPutawayProductInfo");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证
		    Map<String,Object> p= productsWapper.getByProductId(productId);
		    
		    Date dt = new Date();   
		    SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		    
		    Logger.comment("newstart1:"+YMTDateUtil.getFromDTSDate(p.get("newstart").toString(),""));
		    Logger.comment("newstart2:"+YMTDateUtil.parseYMDHMSDate(formatDate.format(dt)));
		    Logger.verifyEquals(true, YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getFromDTSDate(p.get("newstart").toString(),""))
		    		.before(YMTDateUtil.parseYMDHMSDate(formatDate.format(dt))), "验证newstart");
		    
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_017() {
		Logger.start(true,"同步mongo-验证指令ModifyDescTemplate,编辑商品描述模板");
		try{
			SellerProductCallService.deleteTemplate(sellerId);
			SaveProductTemplateBean saveProductTemplateBean=new SaveProductTemplateBean();
			saveProductTemplateBean.setDescription("测试模板");
			saveProductTemplateBean.setPicUrls(Arrays.asList("http://pic1.ymatou.com/G01/shangou/M00/3E/27/rBBlD1tpVJCAHMkLAAH4S4MXnxE909_375_667_n_w_o.jpg"));
			//Integer productTemplateId = TestDataManager.getRandomIntNum(10);
			//saveProductTemplateBean.setProductTemplateId(productTemplateId);
			saveProductTemplateBean.setSellerId(sellerId);
			saveProductTemplateBean.setTemplateName("Test_00" + TestDataManager.getRandomIntNum(5));
			saveProductTemplateBean.setTemplateType(2);
			
			SaveProductTemplateCall saveProductTemplateCall=new SaveProductTemplateCall();
			saveProductTemplateCall.setData(saveProductTemplateBean);
			saveProductTemplateCall.callService();
			
			int templateId=Integer.parseInt(new JSONObject(new JSONObject(saveProductTemplateCall.getReturnData()).get("Data").toString()).get("ProductTemplateId").toString());
			//添加商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getDescModel().setBuyerNoticeId(templateId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//修改模版
			String description="更改测试模板描述_"+ TestDataManager.getRandomIntNum(5);
			String templateName="更改测试模板_"+ TestDataManager.getRandomIntNum(5);
			String picurls="http://pic1.ymatou.com/G01/shangou/M00/3E/27/rBBlD1tpVJCAHMkLAAH4S4MXnxE909_375_667_n_w_o11.jpg";
			saveProductTemplateBean.setProductTemplateId(templateId);
			saveProductTemplateBean.setSellerId(sellerId);
			saveProductTemplateBean.setTemplateName("Test_00" + TestDataManager.getRandomIntNum(5));
			saveProductTemplateBean.setPicUrls(Lists.newArrayList(picurls));
			saveProductTemplateBean.setDescription(description);
			saveProductTemplateBean.setTemplateType(2);

		    saveProductTemplateCall=new SaveProductTemplateCall();
			saveProductTemplateCall.setData(saveProductTemplateBean);
			saveProductTemplateCall.callService();
			//修改库存stock
			//Thread.sleep(10000);
			bean.setActionType("ModifyDescTemplate");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证
		    Map<String,Object> p= productDescExtraWapper.getByProductId(productId);
		    
		    Logger.verifyEquals(description, p.get("notice").toString(), "验证mongo 字段notice");
		    Logger.verifyEquals(picurls, new JSONArray(new JSONObject(p).get("notipics").toString()).get(0), "验证mongo 字段picurls");
		    
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_019() {
		Logger.start(true,"同步mongo-验证指令ModifyPutawayProductInfo,修改上架商品信息(批量)");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> productIds=Lists.newArrayList();
			productIds.add(productId);
			ProductManagerCallServiceV2.batchSetProductOnSale(productIds, sellerId);
			
			YmtCatalogs catalogs=catalogdWapper.selectBySproductId(productId);
			//修改 
			ProductManagerCallServiceV2.updateProductStockNum(sellerId, productId, catalogs.getScatalogid(), 2);
			
			
			bean.setActionType("ModifyPutawayProductInfo");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证
		    Map<String,Object> p= new CatalogsWapper().getByCatalogId(catalogs.getScatalogid());
			Logger.verifyEquals(p.get("stock").toString(), "2", "验证stock返回的库存");
		    
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_020() {
		Logger.start(true,"同步mongo-验证指令ModifyReadyPutawayProductInfo,修改商品待上架信息(批量)");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> productIds=Lists.newArrayList();
			productIds.add(productId);
			
			YmtCatalogs catalogs=catalogdWapper.selectBySproductId(productId);
			//修改 
			ProductManagerCallServiceV2.updateProductStockNum(sellerId, productId, catalogs.getScatalogid(), 2);
			
			ProductManagerCallServiceV2.batchSetProductOnSale(productIds, sellerId);
	
			bean.setActionType("ModifyReadyPutawayProductInfo");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
	        //验证
		    Map<String,Object> p= new CatalogsWapper().getByCatalogId(catalogs.getScatalogid());
			Logger.verifyEquals(p.get("stock").toString(), "2", "验证stock返回的库存");
		    
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_021() {
		Logger.start(true,"同步mongo-验证指令ActivityStockChange,交易更新商品活动库存");
		try{
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);	
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));

			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();
			
			//修改
			int iActivityID=modifyliveactivityBean.getLiveActivity().getLiveActivityId();
			int productInActivityId=modifyliveactivityBean.getLiveActivity().getActivityProducts().get(0).getActivityProductId();
			int transactionId=TestDataManager.getRandomIntNum(9);
			int stockNum=TestDataManager.getRandomIntNum(1);

			Map map=productActStockWapper.selectBy(MapUtil.hashMap("sproductid",productId,"iactivityid",iActivityID));
			int count=productActStockWapper.updateiStockNumByProductActivityStockId(map.get("sProductActivityStockID").toString(),stockNum);
			Logger.comment("stockNum######:"+stockNum);
	       
			//修改库存stock
			bean.setActionType("ActivityStockChange");
			bean.setActivityId(productInActivityId);
			bean.setProductId(productId);
			bean.setTransactionId(transactionId);
			bean.setCatalogId(map.get("sCatalogID").toString());// 规格Id，目前用于交易（包括活动商品）更新库存
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= productActivityStockWapper.getByProdId(productId);
			Logger.verifyEquals(new JSONArray(p.get("catalogs").toString()).getJSONObject(0).getString("stock")
					, Integer.toString(stockNum), "验证mongo返回的库存");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_022() {
		Logger.start(true,"同步mongo-验证指令CatalogStockChange,交易更新商品规格库存");
		try{
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			YmtCatalogs catalogs=catalogdWapper.selectBySproductId(productId);
			
			int transactionId=TestDataManager.getRandomIntNum(9);
			int stockNum=TestDataManager.getRandomIntNum(1);
			
			catalogs.setInum(stockNum);
			int count=catalogdWapper.updateByPrimaryKey(catalogs);
			
			Logger.comment("stockNum######:"+stockNum);
	       
			//修改库存stock
			bean.setActionType("CatalogStockChange");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(transactionId);
			bean.setCatalogId(catalogs.getScatalogid());// 规格Id，目前用于交易（包括活动商品）更新库存
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= new CatalogsWapper().getByCatalogId(catalogs.getScatalogid());
			Logger.verifyEquals(Integer.parseInt(p.get("stock").toString())
					, stockNum, "验证mongo返回的库存");
	
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_023() {
		Logger.start(true,"同步mongo-验证指令ModifyBrandAndCategory,修改商品分类品牌");
		try{
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			YmtProducts product=ymtproductsWapper.selectProductByProductId(productId);
			product.setIbrandid(100);
			product.setIcategoryid(1003);
			int count=ymtproductsWapper.updateByPrimaryKey(product);
			
			int transactionId=TestDataManager.getRandomIntNum(9);
	       
			//修改库存stock
			bean.setActionType("ModifyBrandAndCategory");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(transactionId);
			
			call.setData(bean);
			call.callService();
	        //验证库存stock
		    Map<String,Object> p= new ProductsWapperV2().getByProductId(productId);
			Logger.verifyEquals(p.get("brand").toString()
					, "中文1234", "验证mongo返回的品牌");
			Logger.verifyEquals(p.get("scatid").toString()
					, "1003", "验证mongo返回的分类");
		    Logger.verifyEquals(p.get("tcatname").toString()
							, "按键手机", "验证mongo返回的三级分类名称");
		    Logger.verifyEquals(p.get("scatname").toString()
							, "按键手机", "验证mongo返回的二级分类名称");
			Logger.verifyEquals(p.get("mcatname").toString()
							, "手机通讯", "验证mongo返回的一级分类名称");
	
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_024() {
		Logger.start(true,"同步mongo-验证指令SetPspStatus,设置psp状态");
		try{

			int sellerId=Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			new YmtProductsIWapper().updatePspStatus(productId, 3);
			SetPspStatusBean setpspstatusBean = new SetPspStatusBean();
			SetPspStatusCall setpspstatusCall = new SetPspStatusCall();
			
			setpspstatusBean.setIsPassViolate(true);
			setpspstatusBean.setIsRemovePsp(false);
			setpspstatusBean.setProductId(productId);
			setpspstatusBean.setSellerId(sellerId);
			setpspstatusCall.setData(setpspstatusBean);
			setpspstatusCall.callService();	

			int transactionId=TestDataManager.getRandomIntNum(9);
			//修改
			bean.setActionType("SetPspStatus");
			bean.setActivityId(0);
			bean.setProductId(productId);
			bean.setTransactionId(transactionId);
			
			call.setData(bean);
			call.callService();
	        //验证
		    Map<String,Object> p= new ProductsWapperV2().getByProductId(productId);
			Logger.verifyEquals("true",p.get("ispsp").toString()
					, "验证mongo返回的ispsp");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mongocrud_025() {
		Logger.start(true,"同步mongo-验证指令SyncActivityProduct,同步活动商品");
		try{

			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
			String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String startTime = YMTDateUtil.getBeforeOrNextDayStr(YMTDateUtil.getBeforeOrNextDay(0), 0);
			String productName="修改报名活动名称指令测试_"+startTime;
			new YmtActivityWapper().updateSaleSideName(activityId,productName);
			
			YmtProductsInActivity  productsInActivity=productInActivityWapper.selectAllByiActivityId(activityId).get(0);
			
			bean.setActionType("SyncActivityProduct");
			bean.setActivityId(productsInActivity.getIproductinactivityid());
			bean.setProductId(productId);
			bean.setTransactionId(TestDataManager.getRandomIntNum(9));
			
			call.setData(bean);
			call.callService();
			YmtActivityTemplateWapper ymtActivityTempWapper=new YmtActivityTemplateWapper();
			
			YmtActivity ymtActivity=ymtActivityWapper.getRecordByActivityId(activityId);
			YmtActivityTemplate temp=ymtActivityTempWapper.selectActivityTemplateById(ymtActivity.getIactivitytemplateid());
			// 验证mongo
		    Map<String,Object> p= activityProductsWapper.getByProdId(productId);
			Logger.verifyEquals(p.get("aname").toString(), productName, "验证mongo 表 activityProducts 返回的活动名称");
			Logger.verifyEquals(p.get("alevel").toString(), temp.getActivityLevel().toString(),"验证mongo 表 alevel ");
		}catch(Exception e){
			Logger.fail(e);
		}
	}

}
